package com.cloud.ssh;

import org.springframework.stereotype.Component;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
@Component
public class SshContextListener implements ServletContextListener {
    private SSHConnection sshConnection;

    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        System.out.println("==========>Context initialized...");
        try {
            sshConnection = new SSHConnection();
        } catch (Exception e) {
            e.printStackTrace();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        System.out.println("==========>Context destroyed...");
        try {
            sshConnection.closeSSH();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}